Stomme fout van stefan fixen.. DeleteNode werkt nu weer
[f432xdd.git] / java / Graph Editor / src / controllers / actions / DeleteNode.java
blobc8ef85cacd61e87b9cf689b6b2359ad66faf54c8
1 package controllers.actions;
3 import javax.swing.undo.AbstractUndoableEdit;
5 import models.GraphEdge;
6 import models.GraphVertex;
7 import controllers.*;
9 public class DeleteNode extends AbstractUndoableEdit {
10 private static final long serialVersionUID = -7929100929760152271L;
11 private GraphVertex o;
12 private SelectionController selectionController;
13 private GraphEdge[] affectedEdges;
15 public DeleteNode(SelectionController selectionController)
17 this.selectionController = selectionController;
18 this.o = selectionController.getSelectedVertex();
19 redoAction();
22 private void removeAffectedEdges()
24 selectionController.getModel().removeEdge(affectedEdges);
27 private void addAffectedEdges()
29 selectionController.getModel().addEdge(affectedEdges);
32 private void getAffectedEdges(){
33 GraphEdge[] arr = selectionController.getModel().getEdges();
34 int count = 0;
35 for(int i=0; i < arr.length; i++)
36 if(arr[i].EdgeOf(o))
37 count++;
38 affectedEdges = new GraphEdge[count];
39 count = 0;
40 for(int i=0; i < arr.length; i++)
41 if(arr[i].EdgeOf(o))
42 affectedEdges[count++] = arr[i];
45 private void redoAction()
47 getAffectedEdges();
48 removeAffectedEdges();
49 selectionController.removeSelected();
50 selectionController.getModel().removeGraph(o);
53 public void redo()
55 super.redo();
56 redoAction();
59 public void undo()
61 super.undo();
62 addAffectedEdges();
63 selectionController.getModel().addGraph(o);
64 selectionController.setSelected(o);
66 public boolean isSignificant(){
67 return true;
70 public String getPresentationName(){
71 return "Vertex verwijderen.";